package org.beetl.express;

import org.noear.solon.expression.Expression;
import org.noear.solon.expression.snel.SnEL;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Setup;

import javax.script.ScriptException;
import java.util.LinkedHashMap;
import java.util.Map;

public class Snel extends BaseExpressBenchmark{

	Expression addExpression = null;
	Expression ifExpression = null;
	@Benchmark
	public Object simpleExpress() {
		Map<String,Object> context = new LinkedHashMap<>();
		context.put("arg",getArg());
		return addExpression.eval(context);
	}


	@Benchmark
	@Override
	public Object ifExpresss() {
		Map<String,Object> context = new LinkedHashMap<>();
		context.put("arg",getArg());
		return ifExpression.eval(context);
	}

	@Override
	public Object forExpresss() {
		return null;
	}

	@Setup
	public void init() throws ScriptException {
		addExpression = SnEL.parse("arg.age + (12 + arg.pay)");
		ifExpression = SnEL.parse("arg.age == 10 ? true : false");

	}

	public static void main(String[] args) throws ScriptException {
		Snel spel = new Snel();
		spel.init();
		System.out.println(spel.ifExpresss());
		System.out.println(spel.simpleExpress());
	}
}
